package com.android.kotlincoroutinemvvmdemo.view
import android.content.Context
import android.graphics.Canvas
import android.graphics.Paint
import android.util.AttributeSet
import com.android.kotlincoroutinemvvmdemo.R

/*
* ExploreView
* */
class ExploreView @JvmOverloads constructor(
    context: Context,
    attributeSet: AttributeSet? = null
) : BaseView(context, attributeSet) {

    private val mPaint0 by lazy {
        Paint().apply {
            isAntiAlias = true
            isDither = true
            color = context.resources.getColor(R.color.color_F386C2)
        }
    }

    private val mPaint1 by lazy {
        Paint().apply {
            isAntiAlias = true
            isDither = true
            strokeCap = Paint.Cap.ROUND
            style = Paint.Style.STROKE
            color = context.resources.getColor(R.color.color_CF5C9B)
        }
    }

    override fun onDraw(canvas: Canvas?) {
        super.onDraw(canvas)
        setBackgroundColor(context.resources.getColor(R.color.color_F3F3F3))
        canvas?.apply {
            val cx = mWidth.toFloat() / 2
            val cy = mHeight.toFloat() / 2
            save()
            translate(cx, cy)

            drawCircle(
                0F,
                0F,
                cx * 11 / 12,
                mPaint0
                )

            save()
            rotate(-45F)
            mPaint1.strokeWidth = (cx / 15).coerceAtLeast(minStrokeWidth)
            drawArc(
                -cx * 2 / 5,
                -cy * 6 / 5,
                cx * 2 / 5,
                cy * 6 / 5,
                47F,
                265F,
                false,
                mPaint1
            )
            restore()

            restore()
        }
    }
}